<?php

namespace App\Listeners\Subscriber;

use Illuminate\Events\Dispatcher;
use App\Jobs\Company\CreateSetting;
use App\Events\Company\CreatedEvent;
use App\Events\Company\AcceptedEvent;
use Illuminate\Contracts\Queue\ShouldQueue;

/**
 * 公司数据模型事件订阅者
 *
 * Date: 11/05/2018
 * @author George
 * @package App\Listeners\Subscriber
 */
class CompanyEvnetSubscriber implements ShouldQueue
{
	public function onCreated(CreatedEvent $event)
	{

    }

	/**
	 * 公司审核通过后初始化数据
	 *
	 * Date: 2018/5/30
	 * @author George
	 * @param AcceptedEvent $event
	 */
	public function onAccepted(AcceptedEvent $event)
	{
		// 创建公司的注册设置数据
		CreateSetting::dispatch($event->company);
	}

	/**
	 * 为订阅者注册监听器
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @param Dispatcher $events
	 */
	public function subscribe(Dispatcher $events)
	{
		$events->listen(
			'App\Events\Company\CreatedEvent',
			'App\Listeners\Subscriber\CompanyEvnetSubscriber@onCreated'
		);

		$events->listen(
			'App\Events\Company\AcceptedEvent',
			'App\Listeners\Subscriber\CompanyEvnetSubscriber@onAccepted'
		);
    }
}
